/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox.minigames

import com.almasb.fxgl.app.*
import com.almasb.fxgl.core.util.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.dsl.FXGL.Companion.getMiniGameService
import com.almasb.fxgl.minigames.*
import com.almasb.fxgl.minigames.lockpicking.*
import com.almasb.fxgl.minigames.triggersequence.*
import com.almasb.fxgl.ui.*
import javafx.scene.input.*
import javafx.scene.paint.*
import javafx.scene.text.*

/**
 * @author Almas Baimagambetov (almaslvl@gmail.com)
 */
class MiniGameApp : GameApplication() {
	internal var i = 1
	
	private lateinit var debugText: Text
	
	override fun initSettings(settings: GameSettings) {
		settings.width = 1066
	}
	
	override fun initInput() {
		onKeyDown(KeyCode.F, "Hello") { }
		
		onKeyDown(KeyCode.G, "Hello2") {
			val manager = getMiniGameService()
			manager.startMiniGame(LockPickView()) { result -> println(if(result.isSuccess) "SUCCESS" else "FAIL") }
		}
		
		onKeyDown(KeyCode.H, "Hello3") {}
	}
	
	override fun initGame() {
		debugText = getUIFactory().newText("", Color.BLACK, 36.0)
		
		getGameScene().setBackgroundRepeat("bg_10.png")
		
		addUINode(getUIFactory().newText("Mini-games dev area", Color.BLACK, 48.0), 100.0, 100.0)
		
		val btn = FXGLButton("Trigger Sequence")
		btn.setOnAction {
			val manager = getMiniGameService()
			
			manager.startMiniGame(TriggerSequenceView()) { result ->
				debugText.text = if(result.isSuccess) "Success" else "Fail"
			}
		}
		
		addUINode(debugText, 600.0, 300.0)
		addUINode(btn, 150.0, 150.0)
		addUINode(FXGLButton("Lockpicking"), 150.0, 200.0)
		addUINode(FXGLButton("Trigger Mash"), 150.0, 400.0)
		
		val btnCheck = FXGLButton("Skill Check")
		
		btnCheck.setOnAction { e ->
			val manager = MiniGameService()
			manager.startSweetSpot(10, Consumer { result ->
				debugText.text = if(result.isSuccess) "Success" else "Fail"
			})
		}
		
		addUINode(btnCheck, 150.0, 250.0)
	}
}


fun main(args: Array<String>) {
	GameApplication.launch(MiniGameApp::class.java, args)
}

